****APPENDIX FIGURE B10-B14****

cd "$main_dir/output/figures/appendix_b"

graph set window fontface "Palatino"

//--------------------------------------------------------
//Read in relevant datasets
//--------------------------------------------------------

clear
use "$data_dir/clean/harmonized_pooled_averages.dta"
merge 1:1 ccode using "$data_dir/raw/democ_autoc_switch_media.dta", keepusing(democracy)
drop if _merge==2
drop _merge
merge 1:1 ccode using "$data_dir/raw/average_institutions.dta"
drop if _merge==2
drop _merge
merge 1:1 ccode using "$data_dir/raw/average_gini_coefficients.dta"
drop if _merge==2
drop _merge
merge 1:1 ccode using "$data_dir/raw/average_intentional_homicides.dta"
drop if _merge==2
drop _merge
gen log_avg_10yr_homicides = ln(avg_10yr_homicides)

merge 1:m ccode using "$data_dir/raw/mpd2023_clean.dta"
drop if _merge==2
drop _merge

sort ccode year

local varlist trust_govt_wo trust_govt_dk_ref_wo trust_others media_free avg_10yr_media avg_10yr_gini log_avg_10yr_homicides avg_10yr_freexp
foreach var of local varlist {
	cap drop r`var'
	reg `var' ln_gdppc if year==2008, r
	predict r`var', r
}

//--------------------------------------------------------
//Create Figure B10
//--------------------------------------------------------
scatter rtrust_govt_wo ravg_10yr_gini if year==2008, mlabel(ccode) msize(vsmall) mlabsize(vsmall) mlabcolor(black) legend(off) || lfit rtrust_govt_wo ravg_10yr_gini if year==2008, lcolor(maroon) graphregion(color(white)) bgcolor(white) ylabel(,labs(small) format(%9.2f)) xlabel(,labs(small)) xtitle("Gini Coefficient (conditional)", margin(small) size(small)) ytitle("Trust in Government (conditional)", margin(small) size(small)) 
graph export "figure_b10.png", replace

//--------------------------------------------------------
//Create Figure B11
//--------------------------------------------------------
scatter rtrust_govt_wo rlog_avg_10yr_homicides if year==2008, mlabel(ccode) msize(vsmall) mlabsize(vsmall) mlabcolor(black) legend(off) || lfit rtrust_govt_wo rlog_avg_10yr_homicides if year==2008, lcolor(maroon) graphregion(color(white)) bgcolor(white) ylabel(,labs(small) format(%9.2f)) xlabel(,labs(small)) xtitle("Log(Intentional Homicides per 100,000)", margin(small) size(small)) ytitle("Trust in Government", margin(small) size(small)) 
graph export "figure_b11.png", replace

//--------------------------------------------------------
//Create Figure B12
//--------------------------------------------------------
scatter rmedia_free ravg_10yr_media if year==2008, mlabel(ccode) msize(vsmall) mlabsize(vsmall) mlabcolor(black) legend(off) || lfit rmedia_free ravg_10yr_media if year==2008, lcolor(maroon) graphregion(color(white)) bgcolor(white) ylabel(,labs(small) format(%9.2f)) xlabel(,labs(small)) xtitle("Media Freedom (conditional)", margin(small) size(small)) ytitle("Media Freedom Perceptions (conditional)", margin(small) size(small)) 
graph export "figure_b12.png", replace

//--------------------------------------------------------
//Create Figure B13
//--------------------------------------------------------
scatter rtrust_govt_dk_ref_wo ravg_10yr_freexp if year==2008 & democracy!=1, mlabel(ccode) msize(vsmall) mlabsize(vsmall) mlabcolor(black) legend(off) || lfit rtrust_govt_dk_ref_wo ravg_10yr_freexp if year==2008 & democracy!=1, lcolor(maroon) graphregion(color(white)) bgcolor(white) ylabel(,labs(small) format(%9.2f)) xlabel(,labs(small)) xtitle("Freedom of Expression (conditional)", margin(small) size(small)) ytitle("Trust in Government Non-Response (conditional)", margin(small) size(small)) 
graph export "figure_b13.png", replace

//--------------------------------------------------------
//Create Figure B14
//--------------------------------------------------------
summ rtrust_govt_wo rtrust_others
scatter rtrust_govt_wo rtrust_others if year==2008, mlabel(ccode) msize(vsmall) mlabsize(vsmall) mlabcolor(black) yline(0, lcolor(maroon) lpattern(dash)) xline(0, lcolor(maroon) lpattern(dash)) graphregion(color(white)) bgcolor(white) ylabel(,labs(small) format(%9.2f)) xlabel(,labs(small)) xtitle("Trust in Others (conditional)", margin(small) size(small)) ytitle("Trust in Government (conditional)", margin(small) size(small)) 
graph export "figure_b14.png", replace
